home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / prterr.zip / LPTEST.C < prev    next >
C/C++ Source or Header  |  1993-01-04  |  6KB  |  178 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*    PTRTEST.C - Test program for printer ports.                           */
  4. /*                                                                          */
  5. /*                                                                          */
  6. /*                                                                          */
  7. /*                Copyright 1990, Diebold, Incorporated                     */
  8. /*                                                                          */
  9. /*                                             last date mod ==>  05/11/90  */
  10. /*                                                                          */
  11. /*1 Functions: main, testptr                                                */
  12. /*1                                                                         */
  13. /*                                                                          */
  14. /*7 Author: Brad Stephenson     DATE:  05/11/90                             */
  15. /*                                                                          */
  16. /*8 Revision:                                                               */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /****************************************************************************/
  20.  
  21. #include <stdio.h>
  22. #include <dos.h>
  23. #include <stdlib.h>                 /* for isdigit()                       */
  24. #include <conio.h>                  /* for clrscr()                        */
  25. #include <ctype.h>                  /* for isdigit()                       */
  26. #include <bios.h>                   /* for biosprt()                       */
  27.  
  28. #define DOS_FLUSH_THEN_GETKEY 0x0C
  29. #define ONE   0x01
  30. #define NUL   0x00
  31. #define PRTCH 0x00
  32. #define STAT  0x02
  33.  
  34. union REGS regs;                    /* 80xxx micro registers for DOS calls */
  35.  
  36. char ptrname[2][5] = {"LPT1","LPT2"};
  37.  
  38. int digit,status,port,p;
  39.  
  40. void testptr(int port, int testnum);
  41.  
  42. void main(int argc, char *argv[])
  43.     {
  44.     if (argc>1)
  45.         {
  46.         if ( (*argv[1] != '1') && (*argv[1] != '2') )
  47.             {
  48.             fprintf(stderr,"\nInvalid printer port.  Usage:  LPTEST [1|2]\n");
  49.             exit(1);
  50.             }
  51.         else
  52.             {
  53.             port = atoi(argv[1]);
  54.             }
  55.         }
  56.      else
  57.         {
  58.         port=1;
  59.         }
  60.  
  61.     clrscr();
  62.     fprintf(stderr,"\n\n   This program displays the status of the "
  63.                    "printer port under various error\r\n"
  64.                    "   conditions.  If you would like the results stored "
  65.                    "in a disk file, use DOS\n"
  66.                    "   redirection when calling this program.\n"
  67.                    "\n     For example:  LPTEST >output.fil\n\n");
  68.  
  69.     fprintf(stderr,"   To test LPT2, use:   LPTEST 2\n\n");
  70.  
  71.     fprintf(stderr,"\n1."
  72.     " Turn your printer on, make sure it has paper and is on-line.\n"
  73.     "   Press the Return key when ready...");
  74.     regs.h.ah = DOS_FLUSH_THEN_GETKEY;
  75.     regs.h.al = ONE;
  76.     digit=intdos(®s,®s);
  77.     testptr(port-1,0);
  78.  
  79.     fprintf(stderr,"\n\n2."
  80.     " Make your printer go off-line (press the ON-LINE button once).\n"
  81.     "   Press the Return key when ready...");
  82.     regs.h.ah = DOS_FLUSH_THEN_GETKEY;
  83.     regs.h.al = ONE;
  84.     digit=intdos(®s,®s);
  85.     testptr(port-1,1);
  86.  
  87.     fprintf(stderr,"\n\n3."
  88.     " Place your printer on-line, then remove the paper from the printer.\n"
  89.     "   Press the Return key when ready...");
  90.     regs.h.ah = DOS_FLUSH_THEN_GETKEY;
  91.     regs.h.al = ONE;
  92.     digit=intdos(®s,®s);
  93.     testptr(port-1,2);
  94.  
  95.     fprintf(stderr,"\n\n4."
  96.     " Turn the printer's power switch off.\n"
  97.     "   Press the Return key when ready...");
  98.     regs.h.ah = DOS_FLUSH_THEN_GETKEY;
  99.     regs.h.al = ONE;
  100.     digit=intdos(®s,®s);
  101.     testptr(port-1,3);
  102.  
  103.     fprintf(stderr,"\n\n5."
  104.     " Disconnect the data cable going to the printer.\n"
  105.     "   Press the Return key when ready...");
  106.     regs.h.ah = DOS_FLUSH_THEN_GETKEY;
  107.     regs.h.al = ONE;
  108.     digit=intdos(®s,®s);
  109.     testptr(port-1,4);
  110.     }
  111.  
  112.  
  113. /***************************** D I E B O L D ********************************
  114.  *
  115.  *1  FUNCTION:  testptr
  116.  *
  117.  *2  SUMMARY:  This function tests the printer port to see if it is ready
  118.  *
  119.  *3  INVOCATION: void testptr(ptrport,test)
  120.  *
  121.  *4  INPUTS:  Printer port to be tested, Test number
  122.  *
  123.  *5  OUTPUTS: Displays the results of the three tests; can be redirected.
  124.  *
  125.  *6  CAVEATS:
  126.  *
  127.  *7  AUTHOR: Brad Stephenson     DATE:  05/11/90 
  128.  *
  129.  *8  REVISION:
  130.  *
  131.  ****************************************************************************/
  132.  
  133. void testptr(int ptrport, int test)
  134.  
  135.     {
  136.  
  137.     printf("\n\n   Status of %s port when ",ptrname[ptrport]);
  138.  
  139.     switch(test)
  140.         {
  141.         case 0:
  142.             {
  143.             printf("printer is ready and has paper:\n");
  144.             break;
  145.             }
  146.         case 1:
  147.             {
  148.             printf("printer is off-line:\n");
  149.             break;
  150.             }
  151.         case 2:
  152.             {
  153.             printf("printer is out of paper:\n");
  154.             break;
  155.             }
  156.         case 3:
  157.             {
  158.             printf("printer is powered off:    \n");
  159.             break;
  160.             }
  161.         case 4:
  162.             {
  163.             printf("no printer is attached:\n");
  164.             break;
  165.             }
  166.         default:
  167.             {
  168.             break;
  169.             }
  170.         }
  171.     
  172.     printf("      Initial status : %02X\n",biosprint(STAT,NUL,ptrport) );
  173.     printf("      Printing NULL  : %02X\n",biosprint(PRTCH,NUL,ptrport) );
  174.     printf("      Trailing status: %02X\n",biosprint(STAT,NUL,ptrport) );
  175.  
  176.     }
  177.  
  178.